package com.itheima_32;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateDemo01 {
    public static void main(String[] args) throws ParseException {
        Date d1 = new Date();
        System.out.println(d1);

        long date = 1000 * 60 * 60;
        Date d2 = new Date(date);
        System.out.println(d2);

        Date d3 = new Date();
        System.out.println(d3.getTime() * 1.0 / 1000 / 60 / 60 / 24 / 365 + "年");

        Date d4 = new Date();
        long time = System.currentTimeMillis();
        d4.setTime(time);
        System.out.println(d4);

        Date d5 = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat();
        String s = sdf.format(d5);
        System.out.println(s);

        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf2.format(d5));

        String ss = "2048-08-09 11:11:11";
        Date dd = sdf2.parse(ss); // 将字符串解析为日期对象
        System.out.println(dd);
    }
}
